export default {
	//基地址
	'baseUrl': 'https://bsc.luowangtech.club/',

	//网络请求
	'request': function(options) {
		let url = this.baseUrl + options.url;
		let token = uni.getStorageSync('token');
		console.log('token:',token);
		return new Promise(function(resolve, reject) {
			uni.request({
				method: options.method ? options.method : 'GET',
				url: url,
				data: options.data,
				header: {
					'content-type': 'application/json',
					'token': token ? token : ''
				},
				dataType: options.dataType ? options.dataType : 'json',
				success: function(res) {
					if (res.statusCode == 200) {
						resolve(res.data);
					} else {
						uni.showModal({
							title: '提示',
							showCancel: true,
							cancelText: '取消',
							confirmText: '确认',
							content: res.data,
							success: function(res) {
								if (res.cancel == true) {
									console.log('确认');
								} else if (res.confirm == true) {
									console.log('取消');
								}
							}
						});

					}
				}
			})
		});
	},

	//消息提示
	'toast': function(options = {}) {
		return new Promise(function(resolve, reject) {
			uni.showToast({
				title: options.title ? options.title : '弹出提示',
				icon: options.icon ? options.icon : 'none',
				duration: options.duration ? options.duration : 2000,
				success: function(res) {
					resolve(res);
				},
				fail: function(err) {
					reject(err);
				}
			});
		})
	},

	//弹出框
	'modal': function(options = {}) {
		return new Promise(function(resolve, reject) {
			uni.showModal({
				title: options.title ? options.title : '提示',
				showCancel: options.showCancel ? options.showCancel : true,
				cancelText: options.cancelText ? options.cancelText : '取消',
				confirmText: options.confirmText ? options.confirmText : '确认',
				content: options.content ? options.content : '这是一个模态弹窗',
				success: function(res) {
					resolve(res);
				}
			});
		});
	},

	//选择图片
	'chooseImage': function(count = 0) {
		return new Promise(function(resolve, reject) {
			uni.chooseImage({
				count: count ? count : 1, //默认9
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ['album', 'camera'], //从相册选择
				success: function(res) {
					resolve(res);
				}
			});
		});
	},

	//上传图片
	'upload': function(options) {
		let url = this.baseUrl + options.url;
		return new Promise(function(resolve, reject) {
			uni.uploadFile({
				url: url,
				filePath: options.filePath,
				name: options.name ? options.name : 'file',
				formData: options.formData ? options.formData : {},
				success: (uploadFileRes) => {
					resolve(uploadFileRes)
				}
			});
		});
	}


}
